import { HospitalTypeEnum, type ConsultTypeEnum } from '@/enums'
import type { PartialConsult, illnessType } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 1. 定义数据源
    const consult = ref<PartialConsult>({})

    // 2.选择问诊类型：极速问诊
    const setConsultType = (type: ConsultTypeEnum) => {
      consult.value!.type = type
    }

    const setIllnessTimeType = (type: HospitalTypeEnum) => {
      consult.value.illnessType = type
    }

    // 3.选择科室id
    const setDepId = (id: string) => {
      consult.value.depId = id
    }

    // 4. 填写病情描述
    const setIllness = (data: illnessType) => {
      consult.value.consultFlag = data.consultFlag
      consult.value.illnessDesc = data.illnessDesc
      consult.value.illnessTime = data.illnessTime
      consult.value.pictures = data.pictures
    }

    // 5. 选择患者
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }

    //  6. 存储优惠卷id
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }
    return {
      consult,
      setConsultType,
      setIllnessTimeType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId
    }
  },
  { persist: true } // 自动存到本地存储
)
